package com.lanhai.fnstore.thirdpart;

import com.lanhai.fnstore.Tools;

/**
 * 和科隆威通用，测试
 * @author virus408
 *
 */
public class MaiWei implements StationInterface{

	 

	@Override
	public byte[] clear(int line) {
		 return new byte[] { 0x01 };
	}

	@Override
	public byte[] applyLeave(int line, ApplyTransferEnum type) {
		//注意，这是对接设备的角度
		  return new byte[] { 0x01, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00 };
	}

	@Override
	public StationData resoleveData(byte[] buf) {
		StationData obj=new StationData();
		obj.setCmdStr(Tools.byte2HexStr(buf));
		obj.setLine(buf[0]);
		  if (buf[2] == 0x04 || buf[4] == 0x04)
          {
              //机台异常
			  obj.setEventType(StationDataEnum.Error);
	            return  obj;
          }
          if (buf[2] == 0x03 || buf[4] == 0x03)
          {
              //允许 离开
        	  obj.setEventType(StationDataEnum.AllowLeave); 
         	 return  obj;
          }
          if (buf[2] == 0x02 || buf[4] == 0x02)
          {
        	    //允许 传输
          	obj.setEventType(StationDataEnum.AllowTrans);  
          }
          if(buf[2]==0x01) {
        	  obj.setEventType(StationDataEnum.Info);
          }
        //允许传输的处理 
          int innum=buf[6];
          if (buf[2] == 0x01 || buf[6] > 0)
          {
              //进料
        	   obj.setNeedIn(true);
          }
          int outnum=buf[8];
          if (buf[4] == 0x01 || buf[8] > 0)
          {
              //出料
        	  obj.setNeedOut(true);
          }
          if(outnum>10) outnum=10;
          if(innum>10) innum=10;
          
          //innum 如果为0 ，则机台数量是0，需要上料数量是10
          innum=10-innum;
          
          
          obj.setInNum(innum);
          obj.setOutNum(outnum); 
          return  obj;
	}

	@Override
	public byte[] applyTransfer(int line, ApplyTransferEnum type) {
		//注意，这是对接设备的角度
		byte[] buf = new byte[] { (byte)line, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
		if (type == ApplyTransferEnum.In) {
			// 进料
			buf[2] = 0x01;
			buf[4] = 0x00;
		} else if (type == ApplyTransferEnum.Out) {
			// 出料
			buf[2] = 0x00;
			buf[4] = 0x01;
	 
		}
		return buf;
	}

}
